<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\adminapi\controller\v1\car;


use app\adminapi\controller\AuthController;
use app\services\car\CarDateServices;
use think\facade\App;

/**
 * Class CarDate
 * @package app\adminapi\controller\v1\shendeng
 */
class CarDate extends AuthController
{
    public function __construct(App $app,CarDateServices $services)
    {
        parent::__construct($app);
        $this->services = $services;
    }

    /**
     * 列表
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getList(){
        $where = $this->request->getMore([
            ['id',''],
            ['place_id',''],
            ['time',''],
            ['type_info_id',''],
        ]);
        $field = '*';
        $admin = $this->request->adminInfo();
        if($admin['store_id']) $where['place_id'] = $admin['store_id'];
        return app('json')->success($this->services->getList($where,$field,true));
    }

    /**
     * 添加
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function add(){
        $data = $this->request->postMore([
            ['type_id',''],
            ['book_date',[]],
            ['price_hour',''],
            ['price',''],
            ['day',[]]
        ]);
        $op_user = $this->adminInfo;
        return app('json')->success($this->services->add($data,$op_user,3));
    }

    /**
     * 编辑
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function edit(){
        $data = $this->request->postMore([
            ['id',''],
            ['type_id',''],
            ['edit_date',''],
            ['price_hour',''],
            ['price','']
        ]);
        if(!$data['id']) return app('json')->fail('参数错误');
        $op_user = $this->adminInfo;
        return app('json')->success($this->services->edit($data,$op_user,3));
    }

    /**
     * 删除
     * @return mixed
     */
    public function dateDelete(){
        $data = $this->request->getMore([
            ['ids',[]]
        ]);
        $op_user = $this->adminInfo;
        return app('json')->success($this->services->dateDelete($data['ids'],$op_user,3));
    }

    /**
     * 删除
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function del(){
        $data = $this->request->getMore([
            ['id', 0],
        ]);
        if (!$data['id']) return app('json')->fail('参数错误');
        $op_user = $this->adminInfo;
        return app('json')->success($this->services->delDate((int)$data['id'],$op_user,3));
    }
}
